package org.jeecg.exam;

import cn.hutool.core.date.DateTime;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.TimeZone;

public class FileTime {
    public static void main(String[] args) throws IOException {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String path="C:\\Users\\qing he\\Desktop\\12\\aps\\3.jpg";
        Path path1=Paths.get(path);
        BasicFileAttributes fileAttributes=null;
        fileAttributes = Files.readAttributes(path1, BasicFileAttributes.class);
        java.nio.file.attribute.FileTime creationTime = fileAttributes.creationTime();
        java.nio.file.attribute.FileTime lastAccessTime = fileAttributes.lastAccessTime();
        System.out.println("创建时间"+creationTime);
        System.out.println("更新时间"+lastAccessTime);
        // 获取当前时间
        ZonedDateTime now = ZonedDateTime.now();

        // 获取前一天的零点
        ZonedDateTime startOfYesterday = now.minusDays(1).with(LocalTime.MIN);

        // 获取前一天的 23:59:59
        ZonedDateTime endOfYesterday = now.minusDays(1).with(LocalTime.MAX);

        formatter.format(startOfYesterday);
        formatter.format(endOfYesterday);

        // 输出结果
        System.out.println("前一天零点: " + formatter.format(startOfYesterday));
        System.out.println("前一天 23:59:59: " +   formatter.format(endOfYesterday));


        // 将 FileTime 转换为 Instant
        Instant instant = lastAccessTime.toInstant();

        // 转换为 LocalDateTime，使用系统默认时区
            LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());

        // 如果需要格式化为字符串输出
        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formattedDateTime = dateTime.format(formatter1);
        System.out.println("文件创建时间: " + formattedDateTime);
    }
}
